package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.OrderSettingDao;
import com.itheima.pojo.OrderSetting;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service(interfaceClass = OrderSettingService.class)
public class OrderSettingServiceImpl implements OrderSettingService {
    @Autowired
    private OrderSettingDao orderSettingDao;

    @Override
    public void add(List<OrderSetting> orderSettings) {
        if (orderSettings != null && orderSettings.size() > 0){
            for (OrderSetting orderSetting : orderSettings) {
                Integer count = orderSettingDao.findCountByOrderDate(orderSetting.getOrderDate());
                if (count>0){
                    orderSettingDao.update(orderSetting);
                }else {
                    orderSettingDao.add(orderSetting);
                }
            }
        }
    }

    @Override
    public List<OrderSetting> getOrderSetting(String date) {
        String start = date + "-1";
        String end = date + "-31";
        return orderSettingDao.getOrderSetting(start,end);
    }

    @Override
    public void editNumberByDate(OrderSetting orderSetting) {
        Integer count = orderSettingDao.findCountByOrderDate(orderSetting.getOrderDate());
        if (count>0){
            orderSettingDao.update(orderSetting);
        }else {
            orderSettingDao.add(orderSetting);
        }
    }
}
